import sketch from 'sketch'
import Document from 'sketch/dom'
import util from './util';
import parser from './parser';

const { saveToJson, getSavePathWithPanel } = util;

export default function () {
    const document = Document.getSelectedDocument();
    const selectedLayers = document.selectedLayers;
    const selectedCount = selectedLayers.length;

    if (selectedCount === 0) {
        return sketch.UI.message('⚠️ 选择要导出的海报')
    }

    const savePath = getSavePathWithPanel();
    if (!savePath) return;

    // 默认导出大小是x3
    const baseLayer = selectedLayers.layers[0];
    const resultJson = parser.parse(baseLayer, savePath);
    saveToJson(`${savePath}/output.json`, resultJson);

    sketch.UI.message('导出完成 ✅')
}


